//var produce=getCookie('tokens')
//var name =getCookie('tokens')

// console.log(produce)

function getSearch(key) {
	var s = location.search.slice(1);
	//aa=11 键值对
	//id=2323&aa=11
	console.log(s)
	var arr = s.split('&');

	//["id=2323", "aa=11"]
	console.log(arr)
	for(var i = 0; i < arr.length; i++) {
		console.log(arr[i].split('='))
		var tmpArr = arr[i].split('=');
		if(tmpArr[0] == key) {
			console.log(tmpArr[1])
			return tmpArr[1]
		}
	}
}

//function $(sel) {
//	return document.querySelector(sel)
//}
var h2 = document.querySelector('.productDetails-right h2')
console.log(h2)
var sb2 = document.querySelector('.sb2 span')
var xiang1 = document.querySelector('#xiang1')
var xiang2 = document.querySelector('#xiang2')
var xiang3 = document.querySelector('#xiang3')
var xiang4 = document.querySelector('.bigimg')
var wqid = getSearch("wqid");
console.log(wqid)
$.ajax({
	type: "get",
	url: "http://jx.xuzhixiang.top/ap/api/detail.php",
	async: true,
	data: {
		id: wqid
	},
	success: function(res) {
		var obj = JSON.parse(res);
		console.log(obj)
		var objs = obj.data
		h2.innerHTML = objs.pname
		sb2.innerHTML = objs.pprice
		xiang1.src = objs.pimg
		xiang2.src = objs.pimg
		xiang3.src = objs.pimg
		xiang4.src = objs.pimg

	}
});

//$('.abc').eq(0).hover(function(){
////	$('.abc').eq(0).addClass('classifyActive')
////	num = $(this).index();
////	$('.abc').removeClass('classifyActive')
////	
////	$('.abc').eq(num).addClass('classifyActive')
//console.log(1)
//})
var introduceimg = document.querySelector('.introduce-img')
var introducepinglun = document.querySelector('.introduce-pinglun')
var guochan = document.querySelector('.guochan')
var baozhang = document.querySelector('.baozhang')
var abc = document.querySelectorAll('.abc')
abc[0].onmouseover = function() {
	introduceimg.style.display = 'block'
	introducepinglun.style.display = 'none'
	guochan.style.display = 'none'
	baozhang.style.display = 'none'
	abc[0].className = "abc classifyActive"
	abc[1].className = "abc"
	abc[2].className = "abc"
	abc[3].className = "abc "

}
abc[1].onmouseover = function() {
	introduceimg.style.display = 'none'
	introducepinglun.style.display = 'block'
	guochan.style.display = 'none'
	baozhang.style.display = 'none'
	abc[0].className = "abc"
	abc[1].className = "abc classifyActive"
	abc[2].className = "abc"
	abc[3].className = "abc"
}
abc[2].onmouseover = function() {
	introduceimg.style.display = 'none'
	introducepinglun.style.display = 'none'
	guochan.style.display = 'block'
	baozhang.style.display = 'none'
	abc[0].className = "abc"
	abc[1].className = "abc"
	abc[2].className = "abc classifyActive"
	abc[3].className = "abc"
}
abc[3].onmouseover = function() {
	introduceimg.style.display = 'none'
	introducepinglun.style.display = 'none'
	guochan.style.display = 'none'
	baozhang.style.display = 'block'
	abc[0].className = "abc"
	abc[1].className = "abc"
	abc[2].className = "abc"
	abc[3].className = "abc classifyActive"
}

//放大镜效果
var small = document.querySelector('.small')

var big = document.querySelector('#xiang4')
var zhezhao = document.querySelector('.zhezhao1')
var bigimg = document.querySelector('.bigimg')
var fdj = document.querySelector('.fdj')
fdj.onmouseover = function() {
	zhezhao.style.display = 'block'
	big.style.display = 'block'
}
fdj.onmouseout = function() {
	zhezhao.style.display = 'none'
	big.style.display = 'none'
}
bigimg.style.height = 300 / 100 * 500 + "px"
bigimg.style.width = 300 / 100 * 500 + "px"
//console.log(bigimg.offsetHeight)
//console.log()
var fdjoffsetTops = $(".fdj").offset().top
var fdjoffsetlefts = $(".fdj").offset().left
fdj.onmousemove = function(evt) {
	var offsetX = evt.pageX - fdjoffsetlefts;

	var offsetY = evt.pageY - fdjoffsetTops
	//	console.log(offsetX)
	//	console.log(offsetY)
	let left = offsetX - zhezhao.offsetWidth / 2;
	//	console.log(left)
	let top = offsetY - zhezhao.offsetHeight / 2;
	if(left <= 0) {
		left = 0
	}
	if(left >= fdj.offsetWidth - zhezhao.offsetWidth) {
		left = fdj.offsetWidth - zhezhao.offsetWidth;
	}

	if(top <= 0) {
		top = 0
	}

	if(top >= fdj.offsetWidth - zhezhao.offsetHeight) {
		top = fdj.offsetWidth - zhezhao.offsetHeight;
	}
	zhezhao.style.left = left + "px"
	zhezhao.style.top = top + "px"
	//				var d=bigimg.style.height
	//				console.log(d)
	var w = 300 / 1500;
	var h = 300 / 1500;
	//				console.log(w)
	let bLeft = left / w
	let bTop = top / h
	//				console.log(bLeft)
	bigimg.style.left = -bLeft + 'px'
	bigimg.style.top = -bTop + 'px'

}
var nums = document.querySelector('.duoshage')
var num1 = nums.innerHTML
console.log(num1)
$('.buy-d #youbians').on('click', function() {
	num1++
	console.log(num1)

	//		console.log(nums[num].innerHTML)

	nums.innerHTML = num1

})
$('.buy-d #zuobians').on('click', function() {
	num1--
	if(num1 == 1 || num1 == 0) {
		num1 = 1

	}

	nums.innerHTML = num1

	console.log(nums.innerHTML)
})

$('.gouwus1').eq(0).on('click', function() {
	console.log(1)
		$.ajax({
		type:"get",
		url:"http://jx.xuzhixiang.top/ap/api/add-product.php",
		async:true,
		data:{"uid":15157,"pid":wqid,"pnum":num1},
		success:function(res){
			var obj=JSON.parse(res);
			console.log(obj)
			location.href="gouwuche.html"
		}
		
	});

})
